package com.longge;

public class AlternateDigitSum {

    public int alternateDigitSum(int n) {

        String s = String.valueOf(n);
        boolean flag = true;
        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            int num = s.charAt(i) - '0';
            if (flag){
                ans+=num;
                flag = !flag;
            }else {
                ans-=num;
                flag=!flag;
            }
        }
        return ans;
    }
}
